local skel = fk.CreateSkill {
  name = "lb_zero__xinshi",
}

Fk:loadTranslationTable {
  ["lb_zero__xinshi"] = "心矢",
  [":lb_zero__xinshi"] = "当你的体力值首次变化为一个值后，你的攻击范围+1，然后你可以将手牌数调整至你的攻击范围，若你未因此摸牌，你视为使用一张不可被响应的雷【杀】。",

  ["#lb_zero__xinshi"] = "心矢：你可以弃置一张伤害牌，视为使用 %arg ，若你无法使用则失去1点体力",
  ["#lb_zero__xinshi_draw"] = "心矢：你可以摸 %arg 张牌",
  ["#lb_zero__xinshi_dis"] = "心矢：你可以弃置 %arg 张手牌，然后视为使用一张不可被响应的雷【杀】",
  ["#lb_zero__xinshi_slash"] = "心矢：请视为使用一张不可被响应的雷【杀】",

  ["@[string]lb_zero__xinshi"] = "心矢",

  ["$lb_zero__xinshi1"] = "你听过吗？箭离弦的声音！",
  ["$lb_zero__xinshi2"] = "别把我当病猫。",
}

skel:addEffect(fk.HpChanged, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and
    not table.contains(player:getTableMark("@[string]lb_zero__xinshi"), player.hp)
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    room:addTableMark(player, "@[string]lb_zero__xinshi", player.hp)
    if player:getAttackRange() == player:getHandcardNum() then
      local use = room:askToUseVirtualCard(player, {
        name = "thunder__slash",
        skill_name = skel.name,
        cancelable = false,
        prompt = "#lb_zero__xinshi_slash",
        skip = true,
      })
      if use then
        event:setCostData(self, { use = use })
        room:useSkill(player, self, function()
          self:use(event, target, player, data)
        end, event.skill_data)
      end
    else
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local num = player:getAttackRange() - player:getHandcardNum()
    if num > 0 then
      if room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#lb_zero__xinshi_draw:::" .. num }) then
        event:setCostData(self, { num = num })
        return true
      end
    else
      num = math.abs(num)
      local cards = room:askToDiscard(player, {
        min_num = num,
        max_num = num,
        include_equip = false,
        cancelable = true,
        skill_name = skel.name,
        prompt = "#lb_zero__xinshi_dis:::" .. num,
        skip = true,
      })
      if #cards > 0 then
        event:setCostData(self, { cards = cards })
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).use
    local num = event:getCostData(self).num
    local cards = event:getCostData(self).cards
    player:broadcastSkillInvoke(skel.name)
    room:notifySkillInvoked(player, skel.name, num and "drawcard" or "offensive")
    if cards then
      room:throwCard(cards, skel.name, player)
      if player.dead then return end
      use = room:askToUseVirtualCard(player, {
        name = "thunder__slash",
        skill_name = skel.name,
        cancelable = false,
        prompt = "#lb_zero__xinshi_slash",
        skip = true,
      })
    end
    if use then
      use.disresponsiveList = room.players
      room:useCard(use)
    elseif num and num > 0 then
      player:drawCards(num, skel.name)
    end
  end,
})

skel:addEffect("atkrange", {
  correct_func = function(self, from, to)
    if from:hasSkill("lb_zero__xinshi") then
      return #from:getTableMark("@[string]lb_zero__xinshi")
    end
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@[string]lb_zero__xinshi", 0)
end)

return skel
